package com.ymttest.database.mongo;

import java.util.ArrayList;
import java.util.Map;

import com.ymt.database.MongoDBDriver;

/************************************************************************************
 * @File name :LiveProductInfoWapper.java
 * @Author : xujiewei
 * @Date : 2016年6月28日
 * @Copyright : 洋码头
 * 商品合库 新库
 ************************************************************************************/
public class LiveProductModelWapper {
	MongoDBDriver mdd = YmtMongoDriverFactroy.getInstance_YmtProductDBdriverNew("LiveProductModel");

	public LiveProductModelWapper()  {
	}
		

	public Map<String,Object> getActivityId(int activityId) throws Exception {
		ArrayList<Map> list = mdd.selectPartLimitToMap("{\"LiveId\":" + activityId + "}",1);
	    
	    return list.size()>0?list.get(0):null;
	}
	
	
	public Map<String,Object> getByProductId(String productId) throws Exception {
		//ArrayList<Map> list = mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}",1);
		ArrayList<Map> list = mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}", "", 1, "{'_id':-1}");
	    
	    return list.size()>0?list.get(0):null;
	}
	
	public ArrayList<Map> getLiveProductByProductId(String productId) throws Exception {
		//ArrayList<Map> list = mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}",1);
		ArrayList<Map> list = mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}",101);
	    
	    return list.size()>0?list:null;
	}
	
	public boolean update(Map<String, Object> searchMap,Map<String, Object> updateMap) throws Exception{
		return  mdd.update(searchMap, updateMap).isUpdateOfExisting();
	}
	
	
	public int getCountByActivityId(int activityId) throws Exception{
		return mdd.selectPartLimitToMap("{\"LiveId\":" + activityId + "}",50).size();
	}
	
	
	public static void main(String[] args) throws Exception {
		
	
		System.out.println( new LiveProductModelWapper().getByProductId("28b20646-3218-4936-949f-37b1205c6e59").toString());
		
		
	}    
	
	    
		    	
	
	    
}
